'use strict';
//门店管理
import React,{Component} from 'react';
import Header from '../../common/header';
import * as URLconstant from '../../constant/URLconstant'
import Util from '../../common/util';
import {
    View,
    Text,
    TouchableOpacity,
    Image,
    StyleSheet,
    ScrollView
} from 'react-native';
export default class shopList extends Component{
    // 构造
      constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            shopList:null
        };
      }

    componentDidMount() {
        this.getShopList()
    }

      getShopList(){
          let url = URLconstant.GET_SHOP_LIST
          let datakey=[]
          datakey['user_id']=this.props.user_id
          Util.get(url,datakey,this.getListSuc.bind(this),this.errorCallback.bind(this))
      }
    getListSuc(datas){
        if(datas.status==0){
            this.setState({
                shopList:datas.data
            })
        }else{
            this.setState({
                shopList:[]
            })
        }
    }
    errorCallback(err){

    }


      render(){
          let shopList = this.state.shopList
          return(
              <View style={{flex:1,backgroundColor:"#f0f0f0"}}>
                  <Header navigator={this.props.navigator} initObj={{ title: '门店列表',id:2}}/>
                  {
                      shopList==null?
                          <View style={{flex:1}}>
                              {Util.loading()}
                          </View>:
                          <View style={{flex:1}}>
                              {
                                  shopList.length==0?
                                  <View style={{flex:1, alignItems:'center',justifyContent:'center'}}>
                                      <Text>没有门店列表</Text>
                                  </View>:
                                  <ScrollView style={{flex:1}}>
                                      {
                                          shopList.map((item,index)=>{
                                              return(
                                                  <View style={styles.shop_item} key={index}>
                                                      <Image
                                                          source={require('../../imgs/user.png')}
                                                          resizeMode={'cover'}
                                                          style={{width:50,height:50,borderRadius:25}}
                                                      />
                                                      <View style={styles.item_right}>
                                                          <Text style={{fontSize:16,color:"#000"}}>{item.store_name}({item.real_name})</Text>
                                                          <Text style={{fontSize:14,color:"#969696"}}>{item.area_info}</Text>
                                                      </View>
                                                  </View>
                                              )
                                          })
                                      }
                                  </ScrollView>
                              }
                          </View>
                  }
              </View>
          )
      }
}
var styles = StyleSheet.create({
    shop_item:{
        backgroundColor:"#fff",
        padding:10,
        marginBottom:10,
        flexDirection:'row'
    },
    item_right:{
        flex:1,
        justifyContent:'space-between',
        paddingLeft:10,
        height:50,
    }
})